<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品详情</title>
    <link href="js/kindeditor-4.1.10/themes/default/default.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="js/kindeditor-4.1.10/kindeditor-all-min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/kindeditor-4.1.10/lang/zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="css/jt.css" />
    <script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
    <!-- 自己实现业务逻辑 -->
    <script type="text/javascript" src="js/common.js"></script>

</head>
<body>
<table class="easyui-datagrid" id="itemList" title="景点列表"
       data-options="singleSelect:false,collapsible:true,pagination:true,url:'http://www.shangtour.cn/scenery/pageManage',method:'get',pageSize:20,toolbar:toolbar">
    <thead>
    <tr>
        <th data-options="field:'ck',checkbox:true"></th>
        <th data-options="field:'sceneryId',width:60">景点ID</th>
        <th data-options="field:'sceneryName',width:200">景点名称</th>
        <th data-options="field:'sceneryAddress',width:100">景点地址</th>
        <th data-options="field:'sceneryPrice',width:70,align:'right'">景点价格</th>
        <th data-options="field:'sceneryIntroduce',width:100">景点描述</th>
    </tr>
    </thead>
</table>
<div id="itemEditWindow" class="easyui-window" title="编辑景点" data-options="modal:true,closed:true,iconCls:'icon-save',href:'./item-edit.html'" style="width:80%;height:80%;padding:10px;">
</div>
<script>

    function getSelectionsIds(){
        var itemList = $("#itemList");
        var sels = itemList.datagrid("getSelections");
        var ids = [];
        for(var i in sels){
            ids.push(sels[i].sceneryId);
        }
        ids = ids.join(",");
        return ids;//["200","300","400"]
    }

    var toolbar = [{
        text:'新增',
        iconCls:'icon-add',
        handler:function(){
            $(".tree-title:contains('新增景点')").parent().click();
        }
    },{
        text:'编辑',
        iconCls:'icon-edit',
        handler:function(){
            var ids = getSelectionsIds();
            if(ids.length == 0){
                $.messager.alert('提示','必须选择一个景点才能编辑!');
                return ;
            }
            if(ids.indexOf(',') > 0){
                $.messager.alert('提示','只能选择一个景点!');
                return ;
            }

            $("#itemEditWindow").window({
                onLoad :function(){
                    //回显数据
                    var data = $("#itemList").datagrid("getSelections")[0];
                   $("#itemeEditForm").form("load",data);
                    KindEditorUtil.init({
                        "pics" : data.sceneryImgurl,
                        "cid" : data.cid,
                        fun:function(node){
                            KindEditorUtil.changeItemParam(node, "itemeEditForm");
                        }
                    });
                }
            }).window("open");
        }
    },{
        text:'删除',
        iconCls:'icon-cancel',
        handler:function(){
            var ids = getSelectionsIds();
            if(ids.length == 0){
                $.messager.alert('提示','未选中景点!');
                return ;
            }
            $.messager.confirm('确认','确定删除ID为 '+ids+' 的景点吗？',function(r){
                if (r){
                    var params = {"ids":ids};
                    $.post("/scenery/delete",params, function(data){
                        if(data.status == 200){
                            $.messager.alert('提示','删除景点成功!',undefined,function(){
                                $("#itemList").datagrid("reload");
                            });
                        }
                    });
                }
            });
        }
    },'-',{
        text:'下架',
        iconCls:'icon-remove',
        handler:function(){
            var ids = getSelectionsIds();
            if(ids.length == 0){
                $.messager.alert('提示','未选中景点!');
                return ;
            }
            $.messager.confirm('确认','确定下架ID为 '+ids+' 的景点吗？',function(r){
                if (r){
                    var params = {"ids":ids};
                    $.post("/item/instock",params, function(data){
                        if(data.status == 200){
                            $.messager.alert('提示','下架景点成功!',undefined,function(){
                                $("#itemList").datagrid("reload");
                            });
                        }
                    });
                }
            });
        }
    },{
        text:'上架',
        iconCls:'icon-remove',
        handler:function(){
            var ids = getSelectionsIds();
            if(ids.length == 0){
                $.messager.alert('提示','未选中景点!');
                return ;
            }
            $.messager.confirm('确认','确定上架ID为 '+ids+' 的景点吗？',function(r){
                if (r){
                    var params = {"ids":ids};
                    $.post("/item/reshelf",params, function(data){
                        if(data.status == 200){
                            $.messager.alert('提示','上架景点成功!',undefined,function(){
                                $("#itemList").datagrid("reload");
                            });
                        }
                    });
                }
            });
        }
    }];
</script>
</body>
</html>